home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* */
- /* */
- /* ------------ Bit-Bucket Software <no-Inc> */
- /* \ 10001101 / Writers and Distributors of */
- /* \ 011110 / No-Cost<no-tm> Software. */
- /* \ 1011 / */
- /* ------ */
- /* */
- /* Copyright (C) 1987, 1988, 1989 by Robert Hartman and Vincent Perriello */
- /* */
- /* */
- /* BinkleyTerm File Request Processor */
- /* */
- /* */
- /* For complete details of the licensing restrictions, please refer */
- /* to the License agreement, which is published in its entirety in */
- /* the MAKEFILE and BT.C, and also contained in the file LICENSE.210. */
- /* */
- /* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
- /* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
- /* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
- /* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT THE AUTHORS */
- /* AT THE ADDRESSES LISTED BELOW. IN NO EVENT SHOULD YOU PROCEED TO */
- /* USE THIS FILE WITHOUT HAVING ACCEPTED THE TERMS OF THE */
- /* BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER AGREEMENT AS YOU */
- /* ARE ABLE TO REACH WITH THE AUTHORS. */
- /* */
- /* */
- /* The Authors can be reached at the following addresses: */
- /* */
- /* Robert C. Hartman Vincent E. Perriello */
- /* Spark Software VEP Software */
- /* 427-3 Amherst Street 111 Carroll Street */
- /* CS2032, Suite 232 Naugatuck, CT 06770 */
- /* Nashua, NH 03061 */
- /* */
- /* FidoNet 1:132/101 FidoNet 1:141/491 */
- /* Data (603) 888-8179 Data (203) 729-7569 */
- /* */
- /* Please feel free to contact us at any time to share your comments */
- /* about our software and/or licensing policies. */
- /* */
- /* */
- /* This module is based largely on a similar module in OPUS-CBCS V1.03b. */
- /* The original work is (C) Copyright 1987, Wynn Wagner III. The original */
- /* author has graciously allowed us to use his code in this work. */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <time.h>
-
- #ifdef __TURBOC__
- #include <mem.h>
- #else
- #include <memory.h>
- #endif
-
- #define WAZOO_SECTION
- #include "com.h"
- #include "xfer.h"
- #include "zmodem.h"
- #include "keybd.h"
- #include "sbuf.h"
- #include "sched.h"
- #include "externs.h"
- #include "prototyp.h"
- #include "find.h" /*PLF Fri 05-05-1989 23:54:23 */
-
-
- static char *their_pwd; /* Password in REQ file */
- static char required_pwd[10]; /* Password in OK file */
-
- static int prep_match (char *, char *);
- static int match (char *, char *);
- static void run_prog (char *);
- static int check_password (void);
- static freq_abort (int);
-
- static int prep_match (template, buffer)
- char *template;
- char *buffer;
- {
- register int i, delim;
- register char *sptr;
- int start;
-
- memset (buffer, 0, 11);
-
- i = strlen (template);
- sptr = template;
-
-
- for (start = i = 0; sptr[i]; i++)
- if ((sptr[i] == '\\') || (sptr[i] == ':'))
- start = i + 1;
-
- if (start)
- sptr += start;
- delim = 8; /* last column for ? */
-
- strupr (sptr);
-
- for (i = 0; *sptr && i < 12; sptr++)
- switch (*sptr)
- {
- case '.':
- if (i > 8)
- return (-1);
- while (i < 8)
- {
- buffer[i++] = ' ';
- }
- buffer[i++] = *sptr;
- delim = 12;
- break;
-
- case '*':
- while (i < delim)
- {
- buffer[i++] = '?';
- }
- break;
-
- default:
- buffer[i++] = *sptr;
- break;
-
- } /* switch */
-
- while (i < 12)
- {
- if (i == 8)
- buffer[i++] = '.';
- else buffer[i++] = ' ';
- }
-
- buffer[i] = '\0';
-
- return 0;
- }
-
- static int match (s1, s2)
- char *s1, *s2;
- {
- register char *i, *j;
-
- i = s1;
- j = s2;
-
- while (*i)
- {
- if ((*j != '?') && (*i != *j))
- {
- return 1;
- }
- i++;
- j++;
- }
-
- return 0;
- }
-
- /*--------------------------------------------------------------------------*/
- /* Process file requests from the remote system. The filespec requested is */
- /* turned into a local filespec if possible, then transferred via the */
- /* caller-supplied routine. */
- /*--------------------------------------------------------------------------*/
-
- int n_frproc (request, nfiles, callback)
- char *request;
- int nfiles;
- int (*callback)(char *);
- {
- register int i;
- register int j = 0;
- static char s[80];
- static char s1[80];
- static char s2[80];
-
- FILE *approved;
- FSCAN *dh; /*PLF Fri 05-05-1989 23:48:51 */
- struct stat st;
- char *sptr;
-
- char *after_pwd;
- long updreq = 0L;
- char updtype = 0;
- int saved_nfiles;
-
- char our_wildcard[15];
- char their_wildcard[15];
- int mfunc;
- int magic_state = 0;
-
- int failure_reason = 1; /* 1 = not available */
- /* 2 = no update */
- /* 3 = bad password */
- approved = NULL;
- their_pwd = NULL;
- after_pwd = NULL;
- strcpy (s1, request);
-
- /*--------------------------------------------------------------------*/
- /* Fix up the file name */
- /*--------------------------------------------------------------------*/
- for (i = 0; request[i]; i++)
- {
- if (request[i] <= ' ')
- {
- request[i++] = '\0';
- j = i;
- break;
- }
- }
-
- if (j)
- {
- /* If we have a '!', find the end of the password, point j
- past it, then truncate and fold if necessary. This leaves
- j properly aligned for other fields.
- */
-
- if (request[j] == '!')
- {
- their_pwd = request + (++j);
- for (; request[j]; j++)
- {
- if (request[j] <= ' ')
- {
- request[j++] = '\0';
- break;
- }
- }
-
- if (strlen (their_pwd) > 6)
- their_pwd[6] = '\0';
-
- fancy_str (their_pwd);
- }
-
- /* Test for update/backdate request */
-
- if (request[j] == '+' || request[j] == '-')
- {
- updtype = request[j++];
- updreq = atol (&request[j]);
- }
- }
-
- if (!request[0]) /* Still any filename? */
- return (nfiles); /* If not, return df=0. */
-
- if (freq_abort(nfiles)) /* Any reason to abort? */
- return (-2); /* If so, return error. */
-
-
- /*--------------------------------------------------------------------*/
- /* Initialization(s) */
- /*--------------------------------------------------------------------*/
- i = errno = 0;
- sptr = NULL;
-
- strupr (request);
- status_line ("*%s request (%s)", (updreq != 0L) ? "Update" : "File", request);
-
- saved_nfiles = nfiles;
-
- /*--------------------------------------------------------------------*/
- /* Reserved words */
- /*--------------------------------------------------------------------*/
- if (!strcmp (request, "FILES"))
- {
- if (CurrentFILES)
- strcpy (s, CurrentFILES);
- else
- {
- s[0] = '\0';
- sptr = "No AVAIL list";
- }
- goto avail;
- }
-
- else if (!strcmp (request, "ABOUT"))
- {
- s[0] = '\0';
- goto avail;
- }
-
- prep_match (request, their_wildcard);
-
- /*--------------------------------------------------------------------*/
- /* See if the file is approved for transmission */
- /*--------------------------------------------------------------------*/
- approved = fopen (CurrentOKFile, read_ascii);
- if (got_error (OPEN_msg, CurrentOKFile))
- goto err;
-
- while (!feof (approved))
- {
- /* If we were magic, set flag to cause exit if we don't do it again */
- if (magic_state)
- magic_state = 1; /* 1 means done if no @ */
-
- s[0] = required_pwd[0] = '\0';
-
- fgets (s, 78, approved);
-
- for (i = 0; s[i]; i++)
- if (s[i] == 0x09)
- s[i] = ' ';
- else if (s[i] < ' ')
- s[i] = '\0';
-
- if (!s[0] || s[0] == ';')
- continue;
-
- /*--------------------------------------------------------------*/
- /* Check for transaction-level password */
- /*--------------------------------------------------------------*/
- for (i = 0; s[i]; i++)
- {
- if (s[i] == ' ')
- {
- s[i] = '\0';
- if (s[i + 1] == '!')
- {
- strncpy (required_pwd, s + i + 2, 8);
- if (strlen (required_pwd) > 6)
- required_pwd[6] = '\0';
-
- after_pwd = s + i + 1;
- while (*after_pwd && (!isspace (*after_pwd)))
- ++after_pwd;
-
- if (*after_pwd)
- ++after_pwd;
-
- for (i = 0; required_pwd[i]; i++)
- if (required_pwd[i] <= ' ')
- required_pwd[i] = '\0';
-
- break;
- }
- else
- {
- after_pwd = s + i + 1;
- break;
- }
- }
- else if (s[i] < ' ')
- s[i] = '\0';
- }
-
- if (!s[0])
- continue;
-
- if (strchr ("@+$",s[0]) != NULL)
- {
- /* Magic name or function */
- if (stricmp (&s[1], request))
- continue;
-
- /* Name matches, check password */
- if (!(check_password ()))
- {
- failure_reason = 3; /* Password doesn't match */
- continue; /* Go on */
- }
-
- mfunc = 0;
-
- if (s[0] == '$')
- {
- sprintf (s2, after_pwd, remote_net, remote_node);
- mfunc = 1;
- }
-
- if (s[0] == '+')
- {
- sprintf (s, " %d %d %d", remote_zone, remote_net, remote_node);
- strcpy (s2, s1);
- strcat (s2, s);
- mfunc = 2;
- }
-
- if (mfunc)
- {
- run_prog (s2);
- goto check_HLO;
- }
-
- if (s[0] == '@')
- {
- strcpy (s, after_pwd);
- magic_state = 2; /* Will be reset up above */
- }
- }
-
- /*
- * We're past the magic stuff here. So check for whether this is
- * a new iteration of a magic loop that somehow didn't catch.
- * If not, then check out the filespec we have on this line.
- */
-
- if (magic_state == 1)
- goto check_HLO;
-
- j = 1;
- dh = opendir(); /*PLF Fri 05-05-1989 23:49:02 */
- if (!findfirst(s, _A_NORMAL, dh)) /*PLF Fri 05-05-1989 23:51:03 */
- {
- do
- {
-
- if (!(--j)) /* If we've looped a bit */
- {
- if (i = freq_abort (nfiles)) /* See if we want to quit */
- {
- if (i == 1) /* Yes, why? Carrier? */
- goto finished; /* uh-huh -- get out fast */
- else
- {
- failure_reason = i; /* Not carrier, get reason*/
- goto make_RSP; /* Make a .RSP file */
- }
- }
- j = 10; /* No, reset bounds */
- }
-
- if (!magic_state) /* If not "magic", */
- {
- if (prep_match (dh->name, our_wildcard) < 0)
- continue;
-
- if (match (our_wildcard, their_wildcard))
- continue;
-
- /* File names match, check password now */
-
- if (!check_password ())
- {
- failure_reason = 3; /* Password doesn't match */
- continue; /* Go on */
- }
- }
-
- /* Good password, get full path with wildcard from OKFILE */
-
- strcpy (s2, s);
-
- /* Subtract the wild card file name, keep path */
-
- for (i = strlen (s2); i; i--)
- if (s2[i] == '\\')
- {
- s2[i + 1] = 0;
- break;
- }
-
- /* Then add in the exact name found */
-
- strcat (s2, dh->name);
-
- /* Got full filename, now do file update validation */
-
- if (updtype && !stat (s2, &st))
- {
- if ((updtype == '+' && (st.st_atime - timezone <= updreq))
- || (updtype == '-' && (st.st_atime - timezone >= updreq)))
- {
- failure_reason = 2; /* No update available */
- continue; /* Go on */
- }
- }
-
- /* Everything is OK, send the file if we can */
-
- if ((*callback) (s2))
- ++nfiles;
- j = 1; /* Force abort test */
- }
- while (!findnext(dh)); /*PLF Fri 05-05-1989 23:51:05 */
- } /* if dfind */
-
- else status_line ("!OKFILE ERR `%s'", s); /* if not dfind */
- closedir(dh); /*PLF Fri 05-05-1989 23:51:55 */
- s[0] = '\0';
- } /* while not eof(approved) */
-
- if (saved_nfiles != nfiles)
- failure_reason = 9;
-
- make_RSP:
-
- s[0] = '\0'; /* Initialize string */
- if ((CurrentReqTemplate != NULL) && (dexists(CurrentReqTemplate)))
- {
- Make_Response(s1, failure_reason); /* Build a response */
- strcpy(s, s1); /* Copy it for xmission */
- }
-
- if ((!s[0]) && (failure_reason > 3)) /* if no .RSP file, */
- goto finished; /* give it up */
-
- /*--------------------------------------------------------------------*/
- /* File requested not found, send the system ABOUT file. */
- /*--------------------------------------------------------------------*/
- avail:
-
- if (!s[0])
- {
- if (CurrentAbout)
- strcpy (s, CurrentAbout);
- else
- {
- sptr = "No ABOUT file";
- goto err;
- }
- }
-
- if ((*callback) (s))
- ++nfiles;
-
- goto finished;
-
- /*--------------------------------------------------------------------*/
- /* See if we generated a .QLO file somehow, if so send listed files */
- /*--------------------------------------------------------------------*/
- check_HLO:
-
- i = do_FLOfile ("Q", callback);
- goto finished;
-
- /*--------------------------------------------------------------------*/
- /* Error return */
- /*--------------------------------------------------------------------*/
- err:
- if (sptr)
- status_line ("!%s Request Err: %s", (updreq != 0L) ? "Update" : "File", sptr);
-
- finished:
- if (approved)
- fclose (approved);
- errno = 0;
-
- return (nfiles);
- }
-
- static void run_prog (s)
- char *s;
- {
- status_line (":Executing '%s'", s);
- if (fullscreen && un_attended)
- {
- scr_printf ("\033[H\033[2J");
- }
- scr_printf ("Executing ");
- scr_printf (s);
- scr_printf ("\r\n");
- vfossil_cursor (1);
- b_spawn (s);
- vfossil_cursor (0);
- if (fullscreen && un_attended)
- {
- scr_printf ("\033[H\033[2J");
- sb_dirty ();
- opening_banner ();
- mailer_banner ();
- }
- }
-
- static int check_password ()
- {
- if (required_pwd[0])
- {
- fancy_str (required_pwd);
- if ((strcmp (required_pwd, their_pwd)) &&
- (strcmp (required_pwd, remote_password)))
- {
- status_line ("!Transaction pwd err: %s %s %s",
- required_pwd,
- their_pwd,
- remote_password
- );
-
- return (0);
- }
- }
- return (1);
- }
-
- static int freq_abort (nfiles)
- int nfiles;
- {
- int w_event;
-
- if (!CARRIER)
- {
- status_line ("!Carrier lost, request(s) aborted");
- return (1);
- }
-
- if (nfiles >= CurrentReqLim)
- {
- status_line ("!File Request limit exceeded");
- return (4);
- }
-
- w_event = what_event ();
- if ((w_event >= 0) && (w_event != cur_event))
- {
- if ((e_ptrs[w_event]->behavior & MAT_NOREQ) ||
- ((w_event != cur_event) && (e_ptrs[w_event]->behavior & MAT_FORCED)))
- {
- status_line ("!Event Overrun - requests aborted");
- return (5);
- }
- }
-
- return (0);
- }